import React, { Component } from 'react';
import { Table } from 'antd';
import './Table.css'

const columns = [
  {
    title: '时间',
    dataIndex: 'create_time',
  },
  {
    title: '内容',
    dataIndex: 'content',
  }
];

class LogTable extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: []
    };
  }

  componentDidMount() {
    window.electronAPI.getLog('', (response) => {
      // 在回调函数中处理响应
      const dataList = [];
      response.forEach(item => {
        const newItem = {}
        newItem['create_time'] = item['时间']
        newItem['content'] = item['内容']
        newItem['key'] = item['create_time']
        newItem['id'] = item['create_time']
        dataList.push(newItem)
      }) 

      this.setState({data: dataList})
    });
  }
  
  render() {
    return (
      <Table
        pagination={{ pageSize: 30, total: this.state.data.length,
          showTotal: (total, range) => { return `第${range[0]}-${range[1]}条  共${total} 条`},
        }}
        columns={columns} dataSource={this.state.data} size="small" />
    )
  }

}

export default LogTable;